﻿#include "stdafx.h"
#include "BaseInclude.h"
#include "FrameInclude.h"
#include "SheetInclude.h"
#include "MainWindow.h"
#include <stdlib.h>

#include <QtWidgets/QApplication>
#include <QCoreApplication>
#include <QString>
#include <QProcess>

static QString strExeStartPath = "";

void reLogin()
{
	QProcess process;
	process.startDetached(strExeStartPath);
}

//==================================================================================================
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	strExeStartPath = QCoreApplication::applicationFilePath();

    //加载本地动态库目录
    QString strBinDir = QCoreApplication::applicationDirPath();
    a.addLibraryPath(strBinDir);

	//初始化应用程序
	initApplication();

	LoginDlg login;
	QString SQL = "select USERID ID, DEPTID PID, USERNAME NAME, USERCODE CODE, PASSWD, SHOWORDER from jxd7_xt_user union \
		select ORGANISEID, PREORGANISEID, ORGANISENAME, '', '', SHOWORDER from jxd7_xt_organise order by SHOWORDER";

	if (login.login(SQL, "5AA3D70B-14F9-4A44-8652-3C29DACB70DE") == false)
		return 0;

	const UserInfo & user = LoginDlg::getUserInfo();
	LoginUserInfo * userInfo = LoginUserInfo::getInstance();
	userInfo->initLoginUserInfo(user.strUserID, user.strUserName, user.strUserCode);
	
	MainWindow * window = new MainWindow;
	window->show();

	int iReturn = a.exec();
	if (iReturn == 2)
	{
		atexit(reLogin);
	}
	return iReturn;
}

